import Vue from 'vue'
import Vuex from 'vuex'
import request from '../request.js'
Vue.use(Vuex)
const store = new Vuex.Store({
	state: {
		list: [{
				iconPath: "../../static/tupian5.png",
				selectedIconPath: "../../static/tupian7.png",
				text: '首页',
				// activeColor:'#2491FE',
				// count: 2,
				pagePath: '/pages/index/index',
				isDot: false,
				customIcon: false,
			},
			{
				iconPath: "../../static/tupian74.png",
				selectedIconPath: "../../static/tupian75.png",
				pagePath: '/pages/career/career',
				text: '我的工作',
				// activeColor:'#2491FE',
				customIcon: false,
			},
			{
				iconPath: "../../static/tupian86.png",
				selectedIconPath: "../../static/tupian86.png",
				text: '发布',
				// activeColor:'#2491FE',
				midButton: true,
				customIcon: false,
			},
			{
				iconPath: "../../static/tupian1.png",
				selectedIconPath: "../../static/tupian3.png",
				// activeColor:'#2491FE',
				pagePath: '/pages/campus/campus',
				text: '校园生活',
				customIcon: false,
			},
			{
				iconPath: "../../static/tupian9.png",
				selectedIconPath: "../../static/tupian11.png",
				text: '个人档案',
				pagePath: '/pages/profile/profile',
				// activeColor:'#2491FE',
				// count: 23,
				isDot: false,
				customIcon: false,
			},
		],
		school_district_id: '',
		full_name: '',
	},
	mutations: {
		setState(state, payload) {
			state.school_district_id = payload.school_district_id;
			state.full_name = payload.full_name;
			uni.setStorage({
				key: 'school_district_id',
				data: payload.school_district_id,
				success() {
					console.log('school_district_id缓存成功了');
				},
				fail() {
					console.log('缓存失败了')
				}
			});
			uni.setStorage({
				key: 'full_name',
				data: payload.full_name,
				success() {
					console.log('full_name缓存成功了');
				},
				fail() {
					console.log('缓存失败了')
				}
			});
		}
	},
	actions: {
		//该方法是用于获取用户的个人信息在登录的时候触发但因为vuex刷新就会消失所以有些页面也使用了
		getTodos({
			commit
		}) {
			request({
				url: uni.getStorageSync('host') + 'teacher/user/getMyInfo',
				method: 'get',
				success(res) {
					if (res.statusCode == 200) {
						console.log(res.data.data);
						commit('setState', res.data.data);

					}

				}
			})
		}
	}
})
export default store
